#include <iostream>
using namespace std;
//建立一个简单的时间类，来复习操作符的使用
class time
{
public:
    unsigned int h, m, s, as;
    time() {}
    void update()
    {
        h = as / 3600;
        int p = (as - 3600 * h);
        m = p / 60;
        s = p % 60;
    }
    time(int seconds)
    {
        //使用秒来初始化类
        as = seconds;
        update();
    }
    const char *show()
    {
        char *p = new char[100];
        sprintf(p, "%d:%d:%d", h, m, s);
        return p;
    }
    time operator+(const int seconds)
    {
        //重载加的操作符
        as += seconds;
        update();

        return *this;
    }

    friend time operator+(const int seconds,time &t){
        //友元函数不是member函数
        t.as+=seconds;
        t.update();
        return t;
    }
};
int main()
{
    time a(787);
    cout << a.show() << endl;
    a = a + 21;
    cout << a.show() << endl;
    a = 223 + a;  //这种形式的需要用friend函数
    cout << a.show() << endl;
    return 0;
}
